home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / xgemattest.cc < prev    next >
C/C++ Source or Header  |  1989-08-18  |  5KB  |  161 lines

  1. /*
  2.  *    Test of General Matrix routines for type <T>
  3.  *
  4.  *    Copyright (C) 1988, 1989.
  5.  *
  6.  *    Dr. Thomas Keffer
  7.  *    Rogue Wave Associates
  8.  *    P.O. Box 85341
  9.  *    Seattle WA 98145-1341
  10.  *
  11.  *    Permission to use, copy, modify, and distribute this
  12.  *    software and its documentation for any purpose and
  13.  *    without fee is hereby granted, provided that the
  14.  *    above copyright notice appear in all copies and that
  15.  *    both that copyright notice and this permission notice
  16.  *    appear in supporting documentation.
  17.  *    
  18.  *    This software is provided "as is" without any
  19.  *    expressed or implied warranty.
  20.  *
  21.  *
  22.  *    @(#)xgemattest.cc    2.1    8/18/89
  23.  */
  24.  
  25. /* 
  26. Note that in what follows, explicit type conversions have been used.
  27. For example,
  28.  
  29.     c(1) = <T>(-1.0);
  30.     c[2] = <T>(-2.0);
  31.  
  32. This is for the benefit of type complex.  It is not necessary to do
  33. this when using the GNU compiler and its class Complex (as declared in
  34. Complex.h).  However, it is necessary when using the AT&T class
  35. complex, as declared in complex.h.  I have not tried the GNU Complex.h
  36. file with the AT&T compiler.  
  37. */
  38.  
  39. #define NO_VECTOR_MATHFUN
  40. #include "rw/<A>GEMatrix.h"
  41. #define TYPE <T>_TYPE
  42. #include "vecdefs.h"
  43. #include <stream.h>
  44.  
  45. main()
  46. {
  47.   cout << "\n**** Constructors / destructors ****\n";
  48.   
  49.   // <A>GEMatrix();
  50.   <A>GEMatrix a;
  51.   cout << NL << "<A>GEMatrix a:\n" << a <<NL;
  52.   
  53.   // <A>GEMatrix(int rows, int cols);
  54.   <A>GEMatrix aa(4, 4);
  55.   cout << NL << "<A>GEMatrix aa(4, 4):\n" << aa <<NL;
  56.   
  57.   // <A>GEMatrix(int rows, int cols, <T> initval);
  58.   <A>GEMatrix b(4, 4, <T>(1));
  59.   cout << NL << "<A>GEMatrix b(4, 4, 1):\n" << b <<NL;
  60.  
  61.   // <A>GEMatrix(const <T>Vec&, int, int);
  62.   <A>GEMatrix c(<T>Vec(16, <T>(2)), 4, 4);
  63.   cout << NL << "<A>GEMatrix c(<T>Vec(16,2.0),4,4):\n" << c <<NL;
  64.  
  65.   // <A>GEMatrix(const <A>GEMatrix&);
  66.   <A>GEMatrix d = c;
  67.   cout << NL << "<A>GEMatrix d = c:\n" << d <<NL;
  68.  
  69.   // <A>GEMatrix::deepenShallowCopy();
  70.   d.deepenShallowCopy();
  71.   cout << NL << "d.deepenShallowCopy():\n" << d <<NL;
  72.  
  73.   cout << "\n**** Assignments ****\n";
  74.  
  75.   // <A>GEMatrix        operator=(const <A>GEMatrix&);
  76.   d = b;
  77.   cout << NL << "d = b:\n" << d <<NL;
  78.  
  79.   // <A>GEMatrix        operator=(<T>);
  80.   d = <T>(-1);
  81.   cout << NL << "d = <T>(-1):\n" << d <<NL;
  82.  
  83.   cout << "\n**** Slice and subscripting operators ****\n";
  84.  
  85.   // <T>Slice        operator[](int j);    // Return a col as a slice
  86.   d[1] = <T>(-2);
  87.   cout << NL << "d[1] = <T>(-2):\n" << d <<NL;
  88.  
  89.   //<T>Slice        row(int i);        // Return a row as a slice
  90.   d.row(1) = <T>(-3);
  91.   cout << NL << "d.row(1) = <T>(-3):\n" << d <<NL;
  92.  
  93.   //<T>&        operator()(int i, int j); // Subscripting
  94.   d(1,1) = <T>(-4);
  95.   cout << NL << "d(1,1) = <T>(-4):\n" << d <<NL;
  96.  
  97.   // <T>Vec        diagonal(int idiag=0);    // Return a diagonal as a slice
  98.   d.diagonal(-1) = <T>(-5);
  99.   cout << NL << "d.diagonal(-1) = -5:\n" << d <<NL;
  100.  
  101.   d.diagonal(1) = <T>(5);
  102.   cout << NL << "d.diagonal(1) = 5:\n" << d <<NL;
  103.  
  104.   <A>GEMatrix e(5,4,<T>(1));
  105.   for(int irow=0; irow<e.rows(); irow++)e.row(irow) = <T>(irow);
  106.   cout << NL << "e:\n" << e <<NL;
  107.   cout << NL << "transpose(e):\n" << transpose(e) <<NL;
  108.  
  109.   cout << "\n**** Arithmetic operators ****\n";
  110.  
  111.   cout << NL <<"c:\n" << c <<NL;
  112.   cout << NL <<"d:\n" << d <<NL;
  113.  
  114.   //friend    <A>GEMatrix    operator-(const <A>GEMatrix&);   // Unary minus
  115.   cout << NL <<"-d:\n" << -d <<NL;
  116.  
  117. #if HAS_INCRDECR
  118.   //friend    <A>GEMatrix    operator++(const <A>GEMatrix&);
  119.   cout << NL <<"d++:\n" << d++ <<NL;
  120.  
  121.   //friend    <A>GEMatrix    operator--(const <A>GEMatrix&);
  122.   cout << NL <<"d--:\n" << d-- <<NL;
  123. #endif
  124.  
  125.   //friend    <A>GEMatrix    operator*(const <A>GEMatrix&, const <A>GEMatrix&);
  126.   cout << NL << "d * c:\n" << d * c <<NL;
  127.  
  128. #if HAS_DIVIDE
  129.   //friend    <A>GEMatrix    operator/(const <A>GEMatrix&, const <A>GEMatrix&);
  130.   cout << NL << "d / c:\n" << d / c <<NL;
  131. #endif
  132.  
  133.   //friend    <A>GEMatrix    operator+(const <A>GEMatrix&, const <A>GEMatrix&);
  134.   cout << NL << "d + c:\n" << d + c <<NL;
  135.  
  136.   //friend    <A>GEMatrix    operator-(const <A>GEMatrix&, const <A>GEMatrix&);
  137.   cout << NL << "d - c:\n" << d - c <<NL;
  138.  
  139.   //friend    <A>GEMatrix    operator*(const <A>GEMatrix&, <T>);
  140.   cout << NL << "<T>(2) * d:\n" << <T>(2) * d <<NL;
  141.  
  142. #if HAS_DIVIDE
  143.   //friend    <A>GEMatrix    operator/(const <A>GEMatrix&, <T>);
  144.   cout << NL << "d / <T>(2):\n" << d / <T>(2) <<NL;
  145.  
  146.   //friend    <A>GEMatrix    operator/(<T>, const <A>GEMatrix&);
  147.   cout << NL << "<T>(2) / d:\n" << <T>(2) / d <<NL;
  148. #endif
  149.  
  150.   //friend    <A>GEMatrix    operator+(const <A>GEMatrix&, <T>);
  151.   cout << NL << "<T>(2) + d:\n" << <T>(2) + d <<NL;
  152.  
  153.   // friend    <A>GEMatrix    operator-(const <A>GEMatrix&, <T>);
  154.   cout << NL << "d - <T>(2):\n" << d - <T>(2) <<NL;
  155.  
  156.   // friend    <A>GEMatrix    operator-(<T>, const <A>GEMatrix&);
  157.   cout << NL << "<T>(2) - d:\n" << <T>(2) - d <<NL;
  158.  
  159.   exit(0);
  160. };
  161.